import { createApp } from "vue";
import { createPinia } from "pinia";

import App from "./App.vue";
import router from "./router";
// element
import ElementPlus from "element-plus";
import * as ElementPlusIconsVue from "@element-plus/icons-vue";
// animate
import "animate.css";
//theam
import "element-plus/theme-chalk/dark/css-vars.css";
import "element-plus/dist/index.css";
import "music-box-vue3/dist/style.css";
import "./assets/icons/iconfont/iconfont.css";
import "./style/main.css";
import "./style/special.scss";
import "default-passive-events";
//md
import VMdPreview from '@kangc/v-md-editor/lib/preview';
import vuepressTheme from '@kangc/v-md-editor/lib/theme/vuepress.js';
import '@kangc/v-md-editor/lib/style/base-editor.css';
import '@kangc/v-md-editor/lib/theme/style/vuepress.css';
import Prism from "prismjs";

import { registerMicroApps, start } from 'qiankun';
import { renderWithQiankun, qiankunWindow, QiankunProps } from 'vite-plugin-qiankun/dist/helper'

// import Designer from "@grapecity-software/spread-sheets-designer-vue"


VMdPreview.use(vuepressTheme, {
  Prism,
});

let app = createApp(App) as any;

// app.component("gc-spread-sheets-designer", Designer);

function render() {
  for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
  }
  app.use(createPinia()).use(router).use(ElementPlus).use(VMdPreview);
  app.mount("#app");
}

// 独立运行时
if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
  render()
  console.log('独立运行时')
} else {
  // 作为微应用运行
  console.log('作为微应用运行')
  renderWithQiankun({ // 调用renderWithQiankun
    mount(props) {
      render()
      console.log('-- mount --', props)
    },
    bootstrap() {
      console.log('-- bootstrap --')
    },
    update() {
      console.log('-- update --')
    },
    unmount() {
      console.log('-- unmount --', app)
      app?.unmount()
    }
  })
}